package pers.archives.common.utils.redis;

import lombok.extern.slf4j.Slf4j;
import pers.archives.common.constant.redis.RedisConstant;
import pers.archives.common.ov.OVMenus;

import java.util.List;

import static pers.archives.common.constant.redis.RedisErrorConstant.*;


/*
 *@program:archives-parent
 *@author: 赵浩浩
 *@Time: 2020/9/8  11:10
 */
@Slf4j
public class RedisConstantUtil {

    /**
     * 存储主页菜单栏
     * @param menus 需要存储的数据
     * @param name 当前用户名
     * @return
     */
    public static void setArchiveHomeMenu(List<OVMenus> menus, String name) {
        try {
            RedisUtil.set(RedisConstant.ARCHIVES_HOME_MENU_REDIS + name, menus);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(ARCHIVES_SET_REDIS_WRITE_HOME_MENU_ERROR + e.getMessage());
        }
    }

    /**
     * 获取REDIS中的主页菜单栏信息
     * @param name
     * @return
     */
    public static List<OVMenus> getArchiveHomeMenu(String name) {
        Object o = null;
        try{
            o = RedisUtil.get(RedisConstant.ARCHIVES_HOME_MENU_REDIS  + name);
        } catch (Exception e) {
            log.error(ARCHIVES_GET_REDIS_WRITE_HOME_MENU_ERROR);
        }
        return o == null ? null : (List<OVMenus>) o;
    }
}
